package message

import (
	"git.mycaigou.com/gfyx/micro-gfyx-mp-api/http_server/controller"
	"git.mycaigou.com/gfyx/micro-gfyx-mp-api/infrastructure/common/errcode"
	messageDto "git.mycaigou.com/gfyx/micro-gfyx-mp-api/infrastructure/dto/message"
	"git.mycaigou.com/gfyx/micro-gfyx-mp-api/service/common/message"
	"git.myscrm.cn/golang/stark/v4"
	"github.com/gin-gonic/gin"
)

type VerifyCodeController struct {
	controller.BaseController
	verifyCodeService message.VerifyCodeServiceIface
}

func NewVerifyCodeController(
	verifyCodeService message.VerifyCodeServiceIface,
) *VerifyCodeController {
	return &VerifyCodeController{
		verifyCodeService: verifyCodeService,
	}
}

// RegisterRouter
// 注册路由
func (c *VerifyCodeController) RegisterRouter(g *gin.RouterGroup) {
	//发送短信验证码
	g.POST("/send-sms-code", c.SendSmsCode)
}

func (c *VerifyCodeController) SendSmsCode(ctx *gin.Context) {
	request := &messageDto.SendSmsCodeRequest{}
	if err := ctx.ShouldBind(request); err != nil {
		stark.Logger.Error(ctx, "错误code:", errcode.COMMON_PARAMS_ERROR, ",错误msg:,", err)
		c.Fail(ctx, errcode.COMMON_PARAMS_ERROR, "参数异常")
		return
	}
	rs, err := c.verifyCodeService.SendSmsCode(ctx, request)
	if err != nil {
		stark.Logger.Error(ctx, "错误code:", errcode.COMMON_DATA_NOT_EXIST, ",错误msg:,", err)
		c.Fail(ctx, errcode.COMMON_DATA_NOT_EXIST, "接口返回异常")
		return
	}
	c.Success(ctx, rs)
}
